﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace DotNetCore.BannerManagement.BLL
{
    public class UserManager
    {
        static UserManager instance = null;
        static readonly object padlock = new object();

        public static UserManager GetInstance()
        {

            lock (padlock)
            {
                if (instance == null)
                {
                    instance = new UserManager();
                }
                return instance;
            }

        }


        /// <summary>
        /// Used for a central place to get the current username
        /// Initially put here because the site this was being integrated with
        /// used its own authentication. This will work with straight MembershipProviders
        /// </summary>
        /// <returns></returns>
        public string GetUsername()
        {

            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {

                String username = HttpContext.Current.User.Identity.Name;

                if (username.Contains(";"))
                {
                    return username.Split(Convert.ToChar(";"))[2];
                }
                else
                {
                    return username;
                }

            }

            return String.Empty;

        }

       
    }
}
